**********************************************
***Analysis file for************************** 
***Making Sense of Voting “Habits”: Applying**
***the Process Model of Behavior Change to a**
***Series of Large-Scale Get-Out-the-Vote*****
***Experiments********************************
**********************************************
***Author: John Ternovski*********************
***Assistant Professor and Analyst************
***Office of Labor and Economic Analysis******
***Department of Economics and Geosciences****
***US Air Force Academy***********************
**********************************************
***April 3 2023*******************************
**********************************************

* This .do file requires the following package:
*ssc install ivreg2 

* Load dataset
clear all
use downstream_turnout_full

* Create additional variables 
* Race indicators
gen white=race=="White"
gen black=race=="Black"
gen hisp_ind=race=="Hispanic"

* Democrat indicator 
gen dem=party=="D"
* Income coded as numerical variable
gen catinc_num=1 if catinc=="Less than $20,000"
replace catinc_num=2 if catinc=="$20,000 - $30,000"
replace catinc_num=3 if catinc=="$30,000 - $50,000"
replace catinc_num=4 if catinc=="$50,000 - $75,000"
replace catinc_num=5 if catinc=="$75,000 - $100,000"
replace catinc_num=6 if catinc=="$100,000 - $150,000"
replace catinc_num=7 if catinc=="Greater than $150,000"
* Location variable used for graph code in Supplementary Materials
gen loc="ia" if filenum==1
replace loc="il" if filenum==2
replace loc="mi" if filenum==3
replace loc="ny" if filenum==4
replace loc="wa" if filenum==5
replace loc="pa" if filenum==6
replace loc="ph" if filenum==7
replace loc="nc" if filenum==8
replace loc="va" if filenum==9

save analysis_file, replace


* These are the covariates I use throughout; see SM Section 3 for more details
global covars catinc_num married c.age female white black hisp_ind dem ///
	voted_general_12 voted_general_10 voted_general_08

**********************************************
***************Main Text**********************
**********************************************

***************page 9*************************
* Upstream effect
reg voted i.expercond i.filenum, robust
reg voted i.expercond $covars i.filenum, robust
**********************************************

*****************page 10**********************
* Descriptive Statistics 
* Table 1
tab filenum expercond, row /*This command yields values for Table 1 columns 
titled control, treatment and total*/
tab filenum, sum(voted) /* final column in Table 1 */ 
* Note that "What's on the ballot" and "Population Turnout Rate" columns were 
* taken from online sources such as Ballotopedia, Wikipedia, and local news 
* reporting.
**********************************************

****************page 11***********************
* 2SLS for entire sample minus WA (filenum!=5), since it is a weak instrument; 
* see footnote 19 for more details.
ivreg2 voted18 (voted = expercond) $covars i.filenum if filenum!=5, robust
ivreg2 voted18 (voted = expercond) i.filenum if filenum!=5, robust

* Footnote 19
* Upstream effect of WA only (filenum==5): precise null effect
reg voted expercond $covars if filenum==5, robust
* CACE is larger if we include WA, as expected 
ivreg2 voted18 (voted = expercond) $covars i.filenum, robust
ivreg2 voted18 (voted = expercond) i.filenum, robust
***********************************************

****************page 12************************
* Calculating sample size of Ternovski 2023 in Table 2
count
count if filenum!=5
******************
* Dropping WA for the rest of the analysis; see footnote 19 for more details 
drop if filenum==5
******************

* Footnote 20
* CACE for VA only (filenum==9)
ivreg2 voted18 (voted = expercond) $covars i.filenum if filenum==9, robust 
***********************************************

****************page 13************************
******************
* Prediction 1
******************
* Table 3
reg voted expercond $covars  i.filenum if filenum<6, robust /*upstream effect */
ivreg2 voted_primary_16 (voted = expercond) $covars i.filenum if filenum<6, ///
	robust /* 2016 primary */
ivreg2 voted_general_16 (voted = expercond) $covars i.filenum if filenum<6, ///
	robust  /*2016 general */
ivreg2 voted18 (voted = expercond) $covars i.filenum if filenum<6, robust 
	/* 2018 general */
***********************************************

****************page 14************************
*******************
* Prediction 2
******************
* Table 4
* Low salience elections (PA and Philly only)
local whichif filenum==6 | filenum==7
reg voted expercond $covars i.filenum if `whichif', robust /* upstream */
ivreg2 voted18 (voted = expercond) $covars i.filenum if `whichif', robust 
/* 2018 general */

* High salience elections (all others) 
local whichnotif filenum!=6 & filenum!=7
reg voted expercond $covars i.filenum if `whichnotif', robust /* upstream */
ivreg2 voted18 (voted = expercond) $covars i.filenum if `whichnotif', robust 
/* 2018 general */
***********************************************

****************pages 15-16********************
*******************
* Prediction 3
******************
* Table 5 
* Dem win only (IL filenum==2, MI filenum==3)
local whichif (filenum==2 | filenum==3) & party!="R" 
reg voted expercond $covars i.filenum if `whichif', robust /* upstream */
ivreg2 voted18 (voted = expercond) $covars i.filenum if `whichif', robust ffirst
/* 2018 general */

* Dem loss only (IA filenum==1, NC filenum==8)
local whichnotif (filenum==1 | filenum==8) & party!="R" 
reg voted expercond $covars i.filenum if `whichnotif', robust /* upstream */
ivreg2 voted18 (voted = expercond) $covars i.filenum if `whichnotif', robust ffirst
/* 2018 general */

* Footnote 25
* Low salience downstream persistence doesn't change when Iowa is omitted 
local whichnotif (filenum==8) & party!="R" 
ivreg2 voted18 (voted = expercond) $covars i.filenum if `whichnotif', robust 

* Footnote 27
* Weak-instrument-robust inference
/* Dem win only */ 
local whichif (filenum==2 | filenum==3) & party!="R" 
ivreg2 voted18 (voted = expercond) $covars i.filenum if `whichif', robust ffirst
* Anderson-Rubin Wald test           F(1,975175)=   11.15     P-val=0.0008
/* Dem loss only */ 
local whichnotif (filenum==1 | filenum==8) & party!="R" 
ivreg2 voted18 (voted = expercond) $covars i.filenum if `whichnotif', robust ffirst
* Anderson-Rubin Wald test           F(1,184022)=    0.45     P-val=0.5034

* Foonote 28
* Including VA in the Dem Win category
local whichif filenum==2 | filenum==3 | filenum==9
ivreg2 voted18 (voted = expercond) $covars i.filenum if `whichif', robust
* Similar results 








**************************************************************************
**************************************************************************
*****Supplementary Materials Analyses and Tables**************************
**************************************************************************
**************************************************************************
clear all
use analysis_file

****************page 14************************
* Balance checks 
bysort filenum: logit expercond $covars, robust
***********************************************

****************page 16************************
* Summary statistics
* Table 3.1
gen age18_29=age>=18 & age<=29
gen age30_49=age>=30 & age<=49
gen age50_64=age>=50 & age<=64
gen age65plus=age>=65
tab age18_29 filenum, col
tab age30_49 filenum, col
tab age50_64 filenum, col
tab age65 filenum, col
tab female filenum, col
tab race filenum, col
tab party filenum, col
sum catinc_num, det
bysort filenum: sum catinc_num, det
tab married filenum, col
***********************************************

****************page 17************************
* Vote history summary statistics
* Table 3.2
tab voted_general_12 filenum, col miss
tab voted_general_10 filenum, col miss
tab voted_general_08 filenum, col miss
***********************************************

****************page 20************************
* 5.1 Upstream Effects and CACE at the door 
reg voted expercond $covars i.filenum, robust
ivreg2 voted (canvassed = expercond) $covars i.filenum, robust 
reg voted expercond $covars i.filenum if filenum!=5, robust
ivreg2 voted (canvassed = expercond) $covars i.filenum if filenum!=5, robust 
tab voted if expercond==0
***********************************************

****************page 21************************
* 5.2 Checking for weak instruments 
reg voted expercond $covars if filenum==5, robust
ivreg2 voted18 (voted = expercond) $covars i.filenum if filenum==5, robust ffirst
tab filenum

* Footnote 24
* Weak instrument tests with and without WA
ivreg2 voted18 (voted = expercond) $covars i.filenum, robust ffirst
ivreg2 voted18 (voted = expercond) $covars i.filenum  if filenum!=5, robust ffirst
***********************************************

****************page 22************************
* Table 5.2 
bysort filenum: reg voted expercond $covars i.filenum, robust
bysort filenum: ivreg2 voted (canvassed = expercond) $covars i.filenum, robust
* Set the below to 1==1 to generate Table 5.2 using Stata's putexcel function
if 1==0 {
	putexcel set Table5-2.xlsx, replace

	putexcel A1:H27, hcenter txtwrap vcenter font("Garamond")

	putexcel A1 = "Experiment"
	putexcel B1 = "Intent-to-treat Effect on Upstream Election"
	putexcel C1 = "Treatment-on-Treated Effect on Upstream Election"



	local whichexperiments `"1/9"'
	local whichelection "voted18"
	local linenum 2

	forval i=`whichexperiments' {

		

		local expername : label filenum `i'
		local expername = upper(reverse(substr(reverse(`"`expername'"'),5,.)))
		
		global covars catinc_num married c.age female white black hisp_ind ///
			dem voted_general_12 voted_general_10 voted_general_08
		
		*upstream
		reg voted expercond $covars  i.filenum if filenum==`i', robust
		putexcel B`linenum' = _b[expercond], nformat(0.0000)
		local se_up = _se[expercond]
		
		*ToT
		cap ivreg2 voted (canvassed = expercond) $covars i.filenum if  ///
			filenum==`i', robust

		if !_rc {
			putexcel C`linenum' = _b[canvassed], nformat(0.0000)
			local se_p_16 = _se[canvassed]
		}
		

		
		*writeout names and ses
		putexcel A`linenum' = "`expername'"
		count if filenum==`i'
		local ++ linenum

		putexcel C`linenum' = `se_p_16', nformat("(0.0000)")
		putexcel B`linenum' = `se_up', nformat("(0.0000)")

		putexcel A`linenum' = `"n=`r(N)'"'
		local ++ linenum

	}
}
***********************************************

****************page 23************************
* Weak instrument tests
* Aggregate results
ivreg2 voted18 (voted = expercond) $covars i.filenum if filenum!=5, robust 

* Prediction 1
ivreg2 voted_primary_16 (voted = expercond) $covars i.filenum if filenum<6 & ///
	filenum!=5, robust 
ivreg2 voted_general_16 (voted = expercond) $covars i.filenum if filenum<6 & ///
	filenum!=5, robust 
ivreg2 voted18 (voted = expercond) $covars i.filenum if filenum<6 & ///
	filenum!=5, robust 

* Prediction 2
local whichif filenum==6 | filenum==7 /* Low salience */ 
ivreg2 voted18 (voted = expercond) $covars i.filenum if `whichif', robust 
local whichnotif filenum!=6 & filenum!=7 & filenum!=5 /* High salience */
ivreg2 voted18 (voted = expercond) $covars i.filenum if `whichnotif', robust 

* Prediction 3
local whichnotif (filenum==1 | filenum==8) & party!="R" /* Dem Loss */
ivreg2 voted18 (voted = expercond) $covars i.filenum if `whichnotif', robust ///
	ffirst
local whichif (filenum==2 | filenum==3) & party!="R" /* Dem Win */
ivreg2 voted18 (voted = expercond) $covars i.filenum if `whichif', robust ffirst
***********************************************

****************pages 24-25*********************
* 5.3 Additional predictions
* We need the same covars but with no catincome, since income is the basis of 
* the following subgroup analysis.
global covars_no_inc married c.age female white black hisp_ind  dem voted_general_12 voted_general_10 voted_general_08
sum catinc_num
tab catinc if catinc_num==round(`r(mean)') /* Confirming what mean income is */

* Upstream effects
sum catinc_num /* above mean income */
reg voted expercond $covars_no_inc i.filenum if catinc_num>`r(mean)' & ///
	filenum!=5, robust
sum catinc_num /* below mean income */
reg voted expercond $covars_no_inc i.filenum if catinc_num<=`r(mean)' & ///
	filenum!=5, robust

* CACEs
sum catinc_num  /* above mean income */
ivreg2 voted18 (voted = expercond) $covars_no_inc i.filenum if catinc_num>`r(mean)'  & filenum!=5, robust
sum catinc_num /* below mean income */
ivreg2 voted18 (voted = expercond) $covars_no_inc i.filenum if catinc_num<=`r(mean)'  & filenum!=5, robust
***********************************************

****************pages 25-26********************
* 5.4 Robustness checks 

* Prediction 2, in-text discussion and Table 5.4
* PA and Philly only
local whichif filenum==6 | filenum==7
reg voted expercond $covars i.filenum if `whichif', robust
ivreg2 voted18 (voted = expercond) $covars i.filenum if `whichif', robust 
local whichnotif filenum!=6 & filenum!=7 & filenum!=5
reg voted expercond $covars i.filenum if `whichnotif', robust
ivreg2 voted18 (voted = expercond) $covars i.filenum if `whichnotif', robust 

* PA, Philly, and NY only
local whichif filenum==6 | filenum==7 | filenum==4
reg voted expercond $covars i.filenum if `whichif', robust
ivreg2 voted18 (voted = expercond) $covars i.filenum if `whichif', robust
local whichnotif filenum!=6 & filenum!=7 & filenum!=4 & filenum!=5
reg voted expercond $covars i.filenum if `whichnotif', robust
ivreg2 voted18 (voted = expercond) $covars i.filenum if `whichnotif', robust

* PA, Philly, and VA only
local whichif filenum==6 | filenum==7 | filenum==9
reg voted expercond $covars i.filenum if `whichif', robust
ivreg2 voted18 (voted = expercond) $covars i.filenum if `whichif', robust
local whichnotif filenum!=6 & filenum!=7 & filenum!=9 & filenum!=5
reg voted expercond $covars i.filenum if `whichnotif', robust
ivreg2 voted18 (voted = expercond) $covars i.filenum if `whichnotif', robust

* PA, Philly, NY, and VA only 
local whichnotif filenum>=4 & filenum!=8 & filenum!=5
reg voted expercond $covars i.filenum if `whichnotif', robust
ivreg2 voted18 (voted = expercond) $covars i.filenum if `whichnotif', robust
local whichif filenum<4 | filenum==8
reg voted expercond $covars i.filenum if `whichif', robust
ivreg2 voted18 (voted = expercond) $covars i.filenum if `whichif', robust
***********************************************

****************page 27************************
* Section 6, additional discussion
sum voted_general_16 if expercond==0 & filenum<6 & filenum!=5
sum voted18 if expercond==0 & filenum<6 & filenum!=5
***********************************************

****************page 28************************
* Section 7, Additional Tables and Figures
* Set the following to 1==1 to generate Figure 7.1
* Note that this code requires coefplot
* ssc install coefplot 
if 1==0 {
	cap program drop coef_graph_itt
	program define coef_graph_itt
		
		foreach n in IA IL MI NY WA {
			local state="`n'"
			local statel=lower(`"`state'"')
			cap drop `state'
			gen `state'=expercond if loc==`"`statel'"'
			local options=`"keep(`state') mlabel(@plot) mlabp(1) msymbol(D) msize(medium) vertical nokey yline(0) ytitle("Treatment Effect")"' 

			reg voted_general_14 `state' if loc==`"`statel'"' , robust 
			estimates store _2014
			reg voted_general_16 `state' if loc==`"`statel'"', robust 
			estimates store _2016
			reg voted18 `state' if loc==`"`statel'"' , robust 
			estimates store _2018
			coefplot (_2014, offset(-.1)) (_2016, offset(0)) (_2018, offset(.1)), `options' ylabel(-.01(.01).02) xlabel(1 "`state' General 2014")
			graph save `state'.gph, replace
		}

		
		*************************

		local state="PA"
		local statel=lower(`"`state'"')
		cap drop `state'
		gen `state'=expercond if loc==`"`statel'"'
		local options=`"keep(`state') mlabel(@plot) mlabp(1) msymbol(D) msize(medium) vertical nokey yline(0) ytitle("Treatment Effect")"' 

		reg voted_general_15 `state' if loc==`"`statel'"' , robust 
		estimates store _2015
		reg voted_general_16 `state'  if loc==`"`statel'"' , robust
		estimates store _2016
		reg voted18 `state' if loc==`"`statel'"', robust 
		estimates store _2018
		coefplot (_2015, offset(-.1)) (_2016, offset(0)) (_2018, offset(.1)), `options' ylabel(-.01(.01).02) xlabel(1 "PA Supreme Court 2015")
		graph save `state'.gph, replace

		***********************

		local state="PH"
		local statel=lower(`"`state'"')
		cap drop `state'
		gen `state'=expercond if loc==`"`statel'"'
		local options=`"keep(`state') mlabel(@plot) mlabp(1) msymbol(D) msize(medium) vertical nokey yline(0) ytitle("Treatment Effect")"' 

		reg voted_primary_15 `state' if loc==`"`statel'"', robust 
		estimates store _2015
		reg voted_general_16 `state' if loc==`"`statel'"', robust 
		estimates store _2016
		reg voted18 `state' if loc==`"`statel'"', robust 
		estimates store _2018
		coefplot (_2015, offset(-.1)) (_2016, offset(0)) (_2018, offset(.1)), `options' ylabel(-.01(.01).02) xlabel(1 "Philly Mayoral 2015") 
		graph save `state'.gph, replace

		**********************************
		
		
		local state="NC"
		local statel=lower(`"`state'"')
		cap drop `state'
		gen `state'=expercond if loc==`"`statel'"'
		local options=`"keep(`state') mlabel(@plot) mlabp(1) msymbol(D) msize(medium) vertical nokey yline(0) ytitle("Treatment Effect")"' 

		reg voted_general_16 `state' if loc==`"`statel'"' , robust 
		estimates store _2016
		reg voted18 `state' if loc==`"`statel'"', robust 
		estimates store _2018
		coefplot (_2016, offset(0)) (_2018, offset(.1)), `options' ylabel(-.01(.01).02) xlabel(1 "NC General 2016")
		graph save `state'.gph, replace

		*****************************
		
		local state="VA"
		local statel=lower(`"`state'"')
		cap drop `state'
		gen `state'=expercond if loc==`"`statel'"'
		local options=`"keep(`state') mlabel(@plot) mlabp(1) msymbol(D) msize(medium) vertical nokey yline(0) ytitle("Treatment Effect")"' 

		reg voted_general_17 `state' if loc==`"`statel'"', robust 
		estimates store _2017
		reg voted18 `state' if loc==`"`statel'"', robust 
		estimates store _2018
		coefplot (_2017, offset(0)) (_2018, offset(.1)), `options' ylabel(-.01(.01).02) xlabel(1 "VA General 2017") 
		graph save `state'.gph, replace
		graph combine IA.gph IL.gph MI.gph NY.gph WA.gph PA.gph PH.gph NC.gph VA.gph, title("Canvass Experiment ITT Effects") saving("`1'") rows(4) xsize(10)

	end

	coef_graph_itt ITT.gph

}
***********************************************

****************page 29************************
* Table 7.2
bysort filenum: reg voted expercond $covars, robust
bysort filenum: ivreg2 voted_primary_16 (voted = expercond) $covars, robust
bysort filenum: ivreg2 voted_general_16 (voted = expercond) $covars, robust
bysort filenum: ivreg2 voted18 (voted = expercond) $covars, robust
* Set the following to 1==1 to generate Table 7.2
if 1==0 {
	putexcel set SM_table7-2.xlsx, replace

	putexcel A1:H27, hcenter txtwrap vcenter font("Garamond")

	putexcel A1 = "Experiment"
	putexcel B1 = "1st Stage (Upstream Election)"
	putexcel C1 = "2016 Primary CACE"
	putexcel D1 = "2016 General CACE"
	putexcel E1 = "2018 General CACE"


	local whichexperiments `"1/9"'
	local whichelection "voted_2016_primary voted_2016_general voted18"
	local linenum 2

	forval i=`whichexperiments' {

		

		local expername : label filenum `i'
		local expername = upper(reverse(substr(reverse(`"`expername'"'),5,.)))
		
		global covars catinc_num married c.age female white black hisp_ind  dem voted_general_12 voted_general_10 voted_general_08
		
		*upstream
		reg voted expercond $covars  i.filenum if filenum==`i', robust
		putexcel B`linenum' = _b[expercond], nformat(0.0000)
		local se_up = _se[expercond]
		
		*primary 16
		cap ivreg2 voted_primary_16 (voted = expercond) $covars i.filenum if filenum<8 & filenum==`i', robust
		if _rc {
		
			putexcel C`linenum' = "NA"
			local se_p_16 = 0
		}
		if !_rc {
			putexcel C`linenum' = _b[voted], nformat(0.0000)
			local se_p_16 = _se[voted]
		}
		
		*general 16
		cap ivreg2 voted_general_16 (voted = expercond) $covars i.filenum if filenum<8 & filenum==`i', robust
		if _rc {
			putexcel D`linenum' = "NA"
			local se_g_16 = 0
		}
		if !_rc {
			putexcel D`linenum' = _b[voted], nformat(0.0000)
			local se_g_16 = _se[voted]
		}
		
		*general 18
		cap ivreg2 voted18 (voted = expercond) $covars i.filenum if filenum==`i', robust
		if _rc {
			putexcel E`linenum' = "NA"
			local se_g_18 = 0
		}
		if !_rc {
			putexcel E`linenum' = _b[voted], nformat(0.0000)
			local se_g_18 = _se[voted]
		}
		
		*writeout names and ses
		putexcel A`linenum' = "`expername'"
		count if filenum==`i'
		local ++ linenum

		putexcel E`linenum' = `se_g_18', nformat("(0.0000)")
		putexcel D`linenum' = `se_g_16', nformat("(0.0000)")
		putexcel C`linenum' = `se_p_16', nformat("(0.0000)")
		putexcel B`linenum' = `se_up', nformat("(0.0000)")

		putexcel A`linenum' = `"n=`r(N)'"'
		local ++ linenum

	}
}
***********************************************

****************page 30************************
* All subsequent tables exclude WA, so drop it here
drop if filenum==5

* Table 7.3
reg voted i.expercond $covars  i.filenum if filenum<6 & filenum!=5, robust
margins i.expercond 
reg voted_primary_16 i.expercond $covars  i.filenum if filenum<6 & filenum!=5, robust
margins i.expercond 
reg voted_general_16 i.expercond $covars  i.filenum if filenum<6 & filenum!=5, robust
margins i.expercond 
reg voted18 i.expercond $covars  i.filenum if filenum<6 & filenum!=5, robust
margins i.expercond 
* Set the following to 1==1 to generate Table 7.3
if 1==0 {
	putexcel set table-7-3.xlsx, replace

	putexcel A1:H27, hcenter txtwrap vcenter font("Garamond") nformat(percent_d2)

	putexcel A2 = "Control"
	putexcel A3 = "Treatment"
	putexcel B1 = "2014 General Election"
	putexcel C1 = "2016 Presidential Primary Election"
	putexcel D1 = "2016 Presidential General Election"
	putexcel E1 = "2018 Mid-term General Election"


	reg voted i.expercond $covars  i.filenum if filenum<6 , robust
	margins i.expercond 
	matrix out = r(table)
	putexcel B2 = out[1,1]
	putexcel B3 = out[1,2]

	reg voted_primary_16 i.expercond $covars i.filenum if filenum<6, robust 
	margins i.expercond 
	matrix out = r(table)
	putexcel C2 = out[1,1]
	putexcel C3 = out[1,2]

	reg voted_general_16 i.expercond $covars i.filenum if filenum<6, robust
	margins i.expercond 
	matrix out = r(table)
	putexcel D2 = out[1,1]
	putexcel D3 = out[1,2]

	reg voted18 i.expercond $covars i.filenum if filenum<6, robust 
	margins i.expercond 
	matrix out = r(table)
	putexcel E2 = out[1,1]
	putexcel E3 = out[1,2]
}

****************page 31************************
* Table 7.4
reg voted i.expercond $covars  i.filenum if filenum==6 | filenum==7, robust
margins i.expercond 
reg voted18 i.expercond $covars  i.filenum if filenum==6 | filenum==7, robust
margins i.expercond 
reg voted i.expercond $covars  i.filenum if filenum!=6 & filenum!=7 & filenum!=5, robust
margins i.expercond 
reg voted18 i.expercond $covars  i.filenum if filenum!=6 & filenum!=7 & filenum!=5, robust
margins i.expercond 
* Set the following to 1==1 to generate Table 7.4
if 1==0 {
	putexcel set table7-4.xlsx, replace

	putexcel A1:H27, hcenter txtwrap vcenter font("Garamond") nformat(percent_d2)

	putexcel A2 = "Low salience" 
	putexcel A2:A3, merge
	putexcel A4 = "High salience" 
	putexcel A4:A5, merge
	putexcel B2 = "Control" 
	putexcel B4 = "Control" 
	putexcel B3 = "Treatment"
	putexcel B5 = "Treatment"

	putexcel C1 = "Upstream Election"
	putexcel D1 = "2018 Mid-term General Election"


	reg voted i.expercond $covars i.filenum if filenum==6 | filenum==7, robust
	margins i.expercond 
	matrix out = r(table)
	putexcel C2 = out[1,1]
	putexcel C3 = out[1,2]

	reg voted18 i.expercond $covars i.filenum if filenum==6 | filenum==7, robust
	margins i.expercond 
	matrix out = r(table)
	putexcel D2 = out[1,1]
	putexcel D3 = out[1,2]

	reg voted i.expercond $covars i.filenum if filenum!=6 & filenum!=7, robust
	margins i.expercond 
	matrix out = r(table)
	putexcel C4 = out[1,1]
	putexcel C5 = out[1,2]

	reg voted18 i.expercond $covars i.filenum if filenum!=6 & filenum!=7, robust
	margins i.expercond 
	matrix out = r(table)
	putexcel D4 = out[1,1]
	putexcel D5 = out[1,2]
}


****************page 32************************
* Table 7.5
reg voted i.expercond $covars  i.filenum if (filenum==2 | filenum==3) & party!="R" , robust
margins i.expercond 
reg voted18 i.expercond $covars  i.filenum if (filenum==2 | filenum==3) & party!="R" , robust
margins i.expercond 
reg voted i.expercond $covars  i.filenum if (filenum==1 | filenum==8) & party!="R" , robust
margins i.expercond 
reg voted18 i.expercond $covars  i.filenum if (filenum==1 | filenum==8) & party!="R" , robust
margins i.expercond 
* Set the following to 1==1 to generate Table 7.5
if 1==0 {
	putexcel set table7-5.xlsx, replace

	putexcel A1:H27, hcenter txtwrap vcenter font("Garamond") nformat(percent_d2)

	putexcel A2 = "Dem Win" 
	putexcel A2:A3, merge
	putexcel A4 = "Dem Loss" 
	putexcel A4:A5, merge
	putexcel B2 = "Control" 
	putexcel B4 = "Control" 
	putexcel B3 = "Treatment"
	putexcel B5 = "Treatment"

	putexcel C1 = "Upstream Election"
	putexcel D1 = "2018 Mid-term General Election"

	reg voted i.expercond $covars i.filenum if (filenum==2 | filenum==3) & party!="R" , robust
	margins i.expercond 
	matrix out = r(table)
	putexcel C2 = out[1,1]
	putexcel C3 = out[1,2]

	reg voted18 i.expercond $covars i.filenum if (filenum==2 | filenum==3) & party!="R" , robust
	margins i.expercond 
	matrix out = r(table)
	putexcel D2 = out[1,1]
	putexcel D3 = out[1,2]

	reg voted i.expercond $covars i.filenum if (filenum==1 | filenum==8) & party!="R" , robust
	margins i.expercond 
	matrix out = r(table)
	putexcel C4 = out[1,1]
	putexcel C5 = out[1,2]

	reg voted18 i.expercond $covars i.filenum if (filenum==1 | filenum==8) & party!="R" , robust
	margins i.expercond 
	matrix out = r(table)
	putexcel D4 = out[1,1]
	putexcel D5 = out[1,2]
}




